
A = matrix(c(1,0.5,0,0.5,1,0.5,0,0.5,1),3) ; A

W = solve(A) ; W

prcomp(W)

library(mvtnorm)

M = 100
X = rmvnorm(M, c(0,0,0), W)


cor(X)
fit1 = lm(X[,1] ~ X[,2])

fit2 = lm(X[,3] ~ X[,2])

lm(X[,3] ~ X[,1])

fit1
fit2

cor(fit1$resid, fit2$resid)


